** For "Who Holds Sovereign Debt and Why It Matters" by Fang, Hardy, and Lewis
clear all
set more off
cd "~/Dropbox/Sovereign Bond Project/Replication_Package_submission_RFS"


import excel "Data/Paper_Data/FLZ_Data.xlsx", firstrow clear
destring Year, replace
drop if mi(Total_Debt, Domestic_Total, Domestic_CentralBank, Domestic_Bank, Domestic_NonBank, Foreign_Total, Foreign_Official, Foreign_Bank, Foreign_NonBank)
do "Code/00_Country_Definition.do"

keep if Year>= 2000

encode Country, gen(Country_id)
xtset Country_id Year
by Country_id: gen nyear=[_N]
keep if nyear == 19

distinct Country if AE == 1 // 10
distinct Country if EM == 1 // 27
distinct Country if DC == 1 // 17
replace Country = "AE" if AE == 1
replace Country = "EM" if EM == 1
replace Country = "DC" if DC == 1
collapse (sum) Domestic_Bank Domestic_NonBank Domestic_CentralBank Foreign_Bank Foreign_NonBank Foreign_Official GDP, by(Year Country)

gen DomBk = Domestic_Bank / GDP
gen DomNB = Domestic_NonBank / GDP + DomBk
gen DomCB = Domestic_CentralBank / GDP + DomNB
gen ForBk = Foreign_Bank / GDP + DomCB
gen ForNB = Foreign_NonBank / GDP + ForBk
gen ForOff = Foreign_Official / GDP + ForNB

sort Country Year
label define yearlbl 2000 "00" 2003 "03" 2006 "06" 2009 "09" 2012 "12" 2015 "15" 2018 "18"
label values Year yearlbl

twoway (area ForOff ForNB ForBk DomCB DomNB DomBk Year if Country=="AE", ///
		color("146 153 147" "227 194 145" "130 143 198" "255 236 114" "108 173 225" "194 129 145") ///
		fi(100 100 100 100 100 100 100) ///
		legend(order(6 5) label(6 "DomBk       ") label(5 "DomNB") region(lpattern(blank)) cols(2) pos(6) size(large) bplace(l)) ///
		ytitle("") xtitle("") ///
		xlabel(2000(3)2018, labsize(large) valuelabel tp(i)) ///
		ylabel(0.0(0.2)1.0, labsize(large) angle(horizontal) tp(i)) ///
		scheme(gg_tableau) graphregion(color(white)) ///
		name(Fig2a, replace) xsize(5.1) ysize(5))
graph export "Figures/Figure2a.pdf", replace
graph export "Figures/Figure2a.eps", replace

twoway (area ForOff ForNB ForBk DomCB DomNB DomBk Year if Country=="EM", ///
		color("146 153 147" "227 194 145" "130 143 198" "255 236 114" "108 173 225" "194 129 145") ///
		fi(100 100 100 100 100 100 100) ///
		legend(order(4 3) label(4 "DomCB       ") label(3 "ForBk") region(lpattern(blank)) cols(2) pos(6) size(large) bplace(l)) ///
		ytitle("") xtitle("") ///
		xlabel(2000(3)2018, labsize(large) valuelabel tp(i)) ///
		ylabel(0.0(0.1)0.6, labsize(large) angle(horizontal) tp(i)) ///
		scheme(gg_tableau) graphregion(color(white)) ///
		name(Fig2b, replace) xsize(5.1) ysize(5))		
graph export "Figures/Figure2b.pdf", replace		
graph export "Figures/Figure2b.eps", replace
		
twoway (area ForOff ForNB ForBk DomCB DomNB DomBk Year if Country=="DC", ///
		color("146 153 147" "227 194 145" "130 143 198" "255 236 114" "108 173 225" "194 129 145") ///
		fi(100 100 100 100 100 100 100) ///
		legend(order(2 1) label(2 "ForNB       ") label(1 "ForOff") region(lpattern(blank)) cols(2) pos(6) size(large) bplace(l)) ///
		ytitle("") xtitle("") ///
		xlabel(2000(3)2018, labsize(large) valuelabel tp(i)) ///
		ylabel(0.0(0.2)0.8, labsize(large) angle(horizontal) tp(i)) ///
		scheme(gg_tableau) graphregion(color(white)) ///
		name(Fig2c, replace) xsize(5.1) ysize(5))
graph export "Figures/Figure2c.pdf", replace		
graph export "Figures/Figure2c.eps", replace		   

